#ifndef GLOBAL_H
#define GLOBAL_H

#include "qtjsonsettings/qtjsonsettings.h"
#include "binaryrpc/binaryrpc_server.h"
#include "logmanager/log_global.h"
#include "logencoder/log_encoder.h"
#include "logencoder/log_message_codes.h"
#include "logencoder/log_message_parameters.h"
#include "logencoder/log_app.h"
#include "logencoder/log_class.h"
#include "logencoder/log_obj.h"
#include "dbmanager/database_manager.h"
#include <QtCore/QRegExp>

#ifdef Q_OS_UNIX
static const char LOG_FILE_PATH[]       = "/var/log";
static const char PID_FILE[]            = "/var/run/smsbilling.pid";
static const char DEFAULT_CONFIG_PATH[] =
  "/usr/local/etc/smsbilling/config.json";
#else
static const char LOG_FILE_PATH[]       = "./";
static const char DEFAULT_CONFIG_PATH[] = "config.json";
#endif
static const char APP_NAME[]            = "smsbilling";
static const char APP_VERSION[]         = "1.0.0";
static const QString APP_NAME_VERSION   =
  QString("%1 %2").arg(APP_NAME).arg(APP_VERSION);
static const char HELP[]                =
"  [OPTION]...\n"
"Options:\n"
"    -help | -h       Display this help\n"
"    -version | -v    Display program version\n"
"    -config <path>   Override the default path where user config are stored";

static const char HELP_OPTION1[]        = "-h";
static const char HELP_OPTION2[]        = "-help";
static const char VERSION_OPTION1[]     = "-v";
static const char VERSION_OPTION2[]     = "-version";
static const char CONFIG_OPTION[]       = "-config";

static const char UNIX_DAEMON_CLS[]     = "UnixDaemon";

static const char KERNEL_CLS[]          = "Kernel";

static const char KERNEL_KEY[]          = "kernel";
static const char LOG_LEVEL_KEY[]       = "log_level";
static const char SERVER_ID_KEY[]       = "server_id";
static const char DB_HOST_KEY[]         = "db_host";
static const char DB_PORT_KEY[]         = "db_port";
static const char DB_NAME_KEY[]         = "db_name";
static const char DB_UNAME_KEY[]        = "db_uname";
static const char DB_PASS_KEY[]         = "db_pass";
static const char NUM_CONNECT_DB[]      = "num_connect_db";
static const char EXEC_QUERY_TIMEOUT[]  = "exec_query_timeout";

namespace smsbilling {
  enum State {
    STARTED,
    STARTING,
    ERROR,
    STOPING,
    STOPED
  };

  enum RowState {
    NO_UPDATED,
    UPDATED,
    DELETED,
    ADDED
  };

  class KernelSettings {
  public:
    KernelSettings(quint32 id,
                   const QString &rpc_ip,
                   quint16 rpc_port,
                   const QString &name,
                   quint32 sync_db_time,
                   RowState state = ADDED) :
      id(id),
      rpc_ip(rpc_ip),
      rpc_port(rpc_port),
      name(name),
      sync_db_time(sync_db_time),
      state(state) {

    }

    quint32 id;
    QString rpc_ip;
    quint16 rpc_port;
    QString name;
    quint32 sync_db_time;
    RowState state;
  };

  class TariffAddr {
  public:
    TariffAddr(quint32 id,
               float cost,
               const QRegExp &addr,
               const QRegExp &num,
               RowState state = ADDED) :
      id(id), cost(cost), addr(addr), num(num), state(state) {

    }

    quint32 id;
    float cost;
    QRegExp addr;
    QRegExp num;
    RowState state;
  };

  class Tariff {
  public:
    Tariff(quint32 id,
           const QString &name,
           const QList<TariffAddr *> &addresses,
           RowState state = ADDED) :
      id(id), name(name), addresses(addresses), state(state) {

    }

    quint32 id;
    QString name;
    QList<TariffAddr *> addresses;
    RowState state;
  };

  class Resource {
  public:
    Resource(quint32 id,
             quint32 tariff_id,
             const QString &name,
             float balance,
             quint32 counter,
             quint64 counter_null,
             bool postpaid = false,
             RowState state = ADDED) :
      id(id),
      tariff_id(tariff_id),
      name(name),
      balance(balance),
      postpaid(postpaid),
      counter(counter),
      counter_null(counter_null),
      state(state) {

    }

    quint32 id;
    quint32 tariff_id;
    QString name;
    float balance;
    bool postpaid;
    quint32 counter;
    quint64 counter_null;
    RowState state;
  };

} // namespace smsbilling

#endif // GLOBAL_H
